package com.patui.Utils;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpUtils {
	private final static int CONNECTION_TIMEOUT=60*1000;
	private final static int READ_TIMEOUT=60*1000;
    public static String getStrFromUrlByHttpConn(String strUrl) {
        String result = null;
        HttpURLConnection conn = null;
        InputStream inStream = null;
        ByteArrayOutputStream out = null;
        try {
            URL url = new URL(strUrl);
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setDoOutput(true);
            conn.setConnectTimeout(CONNECTION_TIMEOUT);
            conn.setReadTimeout(READ_TIMEOUT);
            conn.connect();
            int responseCode = conn.getResponseCode();
			if(responseCode==HttpURLConnection.HTTP_OK)
			{
				inStream=conn.getInputStream();
				//result=StreamUtils.readInputStreamToStr(inStream);
			}
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (conn != null)
                    conn.disconnect();
                if (inStream != null)
                	inStream.close();
                if (out != null)
                    out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }

}
